Settings_TimelockFreqAnalysis.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % ADVANCED SETTINGS FOR TIMELOCK / FREQ ANALYSIS: %
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. %
  5. % This settings file will be read by the BuilderGUI.
  6. % - Settings here will be applied to timelocked and frequency analysis.
  7. %
  8. % Usage:
  9. % a) Settings under "DO NOT EDIT" are handled by [MEG]PLS. Do not alter these.
  10. % b) Change other values as needed. See "help" command for FieldTrip section.
  11. % c) Optional settings can be uncommented and specified.
  12. % d) For frequency analysis, choose only one method (comment out others).
  13. %
  14. function [cfgTimelock, cfgTLAvg, cfgGFP, cfgFreq, cfgFreqAvg] = Settings_TimelockFreqAnalysis(handles)
  15. % DO NOT EDIT:
  16. InputFTcfg = handles.FTcfg;
  17. time = handles.time;
  18. gui = handles.gui;
  19. cfgTimelock = InputFTcfg.Timelock;
  20. if isfield(InputFTcfg, 'Freq')
  21. cfgFreq = InputFTcfg.Freq;
  22. end
  23. %--- "FT_TIMELOCKANALYSIS" SETTINGS: ---%
  24. %---------------------------------------%
  25. % DO NOT EDIT:
  26. cfgTimelock.removemean = InputFTcfg.Timelock.removemean;
  27. cfgTimelock.covariancewindow = InputFTcfg.Timelock.covariancewindow;
  28. cfgTimelock.channel = 'MEG';
  29. % GENERAL SETTINGS:
  30. cfgTimelock.covariance = 'yes'; % Note: Auto-enabled for source-filter calculation.
  31. cfgTimelock.keeptrials = 'no'; % Note: Auto-disabled for source-filter calculation.
  32. cfgTimelock.trials = 'all';
  33. cfgTimelock.vartrllength = 0;
  34. %--- "FT_TIMELOCKGRANDAVERAGE" SETTINGS: ---%
  35. %-------------------------------------------%
  36. % DO NOT EDIT:
  37. cfgTLAvg.channel = 'MEG';
  38. cfgTLAvg.latency = 'all';
  39. % GENERAL SETTINGS:
  40. cfgTLAvg.method = 'across'; % Averaging across subjects.
  41. cfgTLAvg.parameter = 'avg';
  42. cfgTLAvg.keepindividual = 'no';
  43. cfgTLAvg.normalizevar = 'N-1';
  44. %--- "FT_GLOBALMEANFIELD" SETTINGS: ---%
  45. %--------------------------------------%
  46. % DO NOT EDIT:
  47. cfgGFP.channel = 'MEG';
  48. % GENERAL SETTINGS:
  49. cfgGFP.method = 'power';
  50. %--- "FT_FREQANALYSIS" SETTINGS: ---%
  51. %-----------------------------------%
  52. % DO NOT EDIT:
  53. cfgFreq.channel = 'MEG';
  54. cfgFreq.method = InputFTcfg.Freq.method;
  55. if strcmp(InputFTcfg.Freq.method, 'mtmfft')
  56. cfgFreq.foilim = [gui.FreqStart, gui.FreqEnd];
  57. else
  58. cfgFreq.foi = [gui.FreqStart : gui.FreqRes : gui.FreqEnd];
  59. end
  60. if ismember(InputFTcfg.Freq.method, {'mtmconvol', 'wavelet'})
  61. cfgFreq.toi = [time.Start : time.Step : time.End];
  62. end
  63. switch gui.FreqMethod
  64. case 'mtmconvol: Fixed Time Win.'
  65. WindowSize = 1 / gui.FreqRes;
  66. cfgFreq.t_ftimwin = ones(length(cfgFreq.foi),1) .* WindowSize;
  67. case 'mtmconvol: Freq. Dep. Time Win.'
  68. DesiredNumCycles = 7; % Exception: Can edit the number of cycles here.
  69. cfgFreq.t_ftimwin = DesiredNumCycles ./ cfgFreq.foi;
  70. end
  71. % IMPORTANT: FOR THE FIXED TIME-WINDOW METHOD, SIZE OF TIME-WINDOW DETERMINES FREQUENCY RESOLUTION.
  72. % - Ex: If you have a 500 ms time-window, you have a 2 Hz frequency resolution (1/0.5s).
  73. %
  74. % IF USING A FIXED TIME-WINDOW METHOD, CHECK THE SIZE OF YOUR TIME-WINDOW:
  75. % - An integer number of oscillatory cycles MUST fit in the time-window specified.
  76. % GENERAL SETTINGS:
  77. cfgFreq.output = 'pow'; % 'pow', 'powandcsd', or 'fourier' (Note: 'powandcsd' auto-enabled for source-filters)
  78. cfgFreq.trials = 'all';
  79. cfgFreq.keeptrials = 'no'; % Note: Auto-disabled for source-filter calculation.
  80. cfgFreq.keeptapers = 'no';
  81. % FOR DICS SOURCE ANALYSIS ON MTMFFT DATA, CONFIGURATION CAN BE SET AS FOLLOWS:
  82. % See summary below to configure freq. analysis settings for DICS.
  83. %
  84. % Link to FT tutorial:
  85. % fieldtrip.fcdonders.nl/tutorial/beamformer
  86. %
  87. % EXAMPLE: If interested in DICS source analysis for 40-70Hz.
  88. % - In the GUI, set the start & end frequency to 55Hz (middle of frequency range).
  89. % In source analysis adv. settings, set cfg.frequency for DICS beamformer to 55Hz as well.
  90. %
  91. % - Set "tapsmofrq" (smoothing) to accomodate the desired frequency band.
  92. % For the example above, set "tapsmofrq" to 15Hz (smoothing window of +/- 15).
  93. % Make sure that taper type is set to "dpss" or "tapsmofrq" will have no effect.
  94. %
  95. % - Amount of smoothing is dependent on desired frequency band.
  96. % In general, for higher frequencies, you want to increase the width of the smoothing.
  97. % FOR MTMFFT OR MTMCONVOL METHODS:
  98. cfgFreq.taper = 'hanning'; % 'hanning' or 'dpss'
  99. if strcmp(cfgFreq.taper, 'dpss')
  100. if strcmp(cfgFreq.method, 'mtmfft') % FOR MTMFFT
  101. cfgFreq.tapsmofrq = 4; % Note: Value of 1 is effectively no smoothing.
  102. elseif strcmp(cfgFreq.method, 'mtmconvol') % FOR MTMCONVOL
  103. cfgFreq.tapsmofrq = 0.4 * cfgFreq.foi; % Note: Smoothing increases with frequency.
  104. % Use smaller values for less smoothing.
  105. end
  106. end
  107. % "tapsmofrq" is the amount of spectral smoothing through dpss multi-tapering.
  108. % - For "mtmfft": This should be a single number.
  109. % - For "mtmconvol": This is a vector (1 x NumFOI).
  110. %
  111. % Smoothing window will be +/- the value specified.
  112. % - Ex: If "tapsmofrq" = 4, then smoothing window is an 8 Hz box (+/- 4).
  113. %
  114. % Example: For DICS source analysis, if interested in frequency band of 40 - 70 Hz:
  115. % - Set frequency of interest (cfg.foi) to 55 Hz with a smoothing window of +/- 15 Hz.
  116. % Don't forget to set cfgSource.frequency to 55 Hz as well.
  117. %
  118. % Note: For time-freq analyses, for lower frequencies (i.e < 15 Hz), Hanning window is recommended over dpss.
  119. % - Smoothing for dpss may not be applicable for lower frequencies.
  120. % - Ex: If running "mtmfft" with foi of 2-30Hz, cannot smooth by more than 2Hz.
  121. %
  122. % For more info, see: http://fieldtrip.fcdonders.nl/tutorial/timefrequencyanalysis
  123. % FOR WAVELET OR TFR METHODS:
  124. cfgFreq.width = 7; % Number of cycles of the wavelet (Default = 7).
  125. cfgFreq.gwidth = 3; % (Default = 3)
  126. % OPTIONAL SETTINGS:
  127. % cfgFreq.pad
  128. % cfgFreq.padtype
  129. % cfgFreq.polyremoval
  130. % cfgFreq.channelcmb = {'MEG', 'MEG'};
  131. %--- "FT_FREQGRANDAVERAGE" SETTINGS: ---%
  132. %---------------------------------------%
  133. % DO NOT EDIT:
  134. cfgFreqAvg.channel = 'MEG';
  135. cfgFreqAvg.foilim = 'all';
  136. cfgFreqAvg.toilim = 'all';
  137. % GENERAL SETTINGS:
  138. cfgFreqAvg.parameter = 'powspctrm';
  139. cfgFreqAvg.keepindividual = 'no';